#!/bin/sh

set -e

if [ $# -lt 2 ]; then
	echo "Wrapper for run linux kernel make"
	echo "Usage:"
	echo "$0 [ DEST dir ] [ SOURCE dir ] [ files ... ] -- [ options for make ... ]"
	exit 1
fi

dstdir=$1
shift
srcdir=$1
shift

while [ $# -ne 0 ]; do
	case $1 in
	--)
		shift
		break
		;;
	*)
		dst=$dstdir/${1#$srcdir/}
		mkdir -p ${dst%/*}
		[ $dst -nt $1 ] || ln -fsnr $1 $dst
		shift
		;;
	esac
done

make $*
